package com.guigu.tomcat.impl;

import com.guigu.tomcat.Cookie;

public class CookieImpl implements Cookie {

    private String domain;
    private  String name;
    private String value;
    private String path;
    private  Integer maxAge;

    public CookieImpl(String name, String value) {
        this.name = name;
        this.value = value;

    }

    @Override
    public void setDomain(String pattern) {
        this.domain =pattern;
    }

    @Override
    public void setMaxAge(int expiry) {
this.maxAge = expiry;
    }

    @Override
    public void setPath(String uri) {
this.path =uri;

    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getValue() {
        return value;
    }

    @Override
    public String toString() {
        //c=xxx Max-Age=9999;
        String ret =name +"="+value;
        if (maxAge!=null){
            ret += ";Max-Age="+maxAge;
    }
        if (path!=null){
            ret += ";Max-Age="+path;
        }
        if (domain!=null){
            ret += ";Max-Age="+domain;
        }
        return ret;


    }
}
